﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong.XmlHttp;
using System.Text.RegularExpressions;
public partial class aspnet_admin_bock_collect_CollectExe_testCont : System.Web.UI.Page
{
    Tong.TongUse TextData = new Tong.TongUse();
    GetWebData webDate = new GetWebData();
    public string pageURL = "";//页面地址
    /// <summary>
    /// 得到标题的与正则
    /// </summary>
    public string StrTitle = ""; // 得到标题的与正则

    /// <summary>
    /// 得到内容的正则
    /// </summary>
    public String StrCont = ""; //  得到内容的正则
    public string pagecode = "";

    public string Scont ="";

    /// <summary>
    /// 要读取数据的页面
    /// </summary>
    public String Linkurl ="";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["LinkPage"] != null)//如果有LINK路径的话
        {
            Linkurl = Session["LinkPage"].ToString();
            pagecode = Request.QueryString["pagecode"].Trim();
            pageURL = Request.QueryString["pageURL"].Trim();
            StrTitle = Request.QueryString["RegexStrTitle"].Trim();
            StrCont = Request.QueryString["RegexStrCont"].Trim();

            //开始得到各标签 是不是不要
            bool TagA = Convert.ToBoolean(Request.QueryString["TagA"].ToString());
            bool TagObject = Convert.ToBoolean(Request.QueryString["TagObject"].ToString());
            bool TagHTML = Convert.ToBoolean(Request.QueryString["TagHTML"].ToString());
            bool TagSTYLE = Convert.ToBoolean(Request.QueryString["TagSTYLE"].ToString());
            bool TagDIV = Convert.ToBoolean(Request.QueryString["TagDIV"].ToString());
            bool TagCLASS = Convert.ToBoolean(Request.QueryString["TagCLASS"].ToString());
            bool TagFONT = Convert.ToBoolean(Request.QueryString["TagFONT"].ToString());
            bool TagSPAN = Convert.ToBoolean(Request.QueryString["TagSPAN"].ToString());
            bool TagIFRAME = Convert.ToBoolean(Request.QueryString["TagIFRAME"].ToString());
            bool TagSCRIPT = Convert.ToBoolean(Request.QueryString["TagSCRIPT"].ToString());

            urlx.Text = pageURL;

            try
            {
                Scont = webDate.GetWebDate(Linkurl, pagecode);
                LabTitel.Text = Regex.Replace(Regex.Match(Scont, RegexStrxContTitle(StrTitle)).Value, @"<\/*[^<>]*>", "").Replace(" ", "").Replace("&nbsp;","");
               // LabTitel.Text =Regex.Match(Scont, RegexStrxContTitle(StrTitle)).Value;
                Scont = Regex.Match(Scont, RegexStrxCont(StrCont)).Value;//搜索到的内容
                #region 开始定义标签 用于把文章里的东东全干掉

                string ATag = @"<(\/){0,1}a[^<>]*>";///A标签
                string ObjectTag = @"<object.*?/object>";///object 标签
                string StyleTag = @"(<style){1,}[^<>]*>[^\0]*(<\/style>){1,}";/// style                            
                string DivTag = @"<(\/){0,1}div[^<>]*>";//Div
                string HTMLTag = @"<\/*[^<>]*>";
                string CLASSTag = @"(class=){1,}(""|\'){0,1}\S+(""|\'|>|\s){0,1}";
                string FONTTag = @"<(\/){0,1}font[^<>]*>";
                string SPANTag = @"<(\/){0,1}span[^<>]*>";
                string IFRAMETag = @"(<iframe){1,}[^<>]*>[^\0]*(<\/iframe>){1,}";
                string SCRIPTTag = @"(<script){1,}[^<>]*>[^\0]*(<\/script>){1,}";

                if (TagA)
                {
                    Scont = Regex.Replace(Scont, ATag, "");
                }
                if (TagObject)
                {
                    Scont = Regex.Replace(Scont, ObjectTag, "");
                }

                if (TagSTYLE)
                {
                    Scont = Regex.Replace(Scont, StyleTag, "");
                }

                if (TagDIV)
                {
                    Scont = Regex.Replace(Scont, DivTag, "");
                }

                if (TagCLASS)
                {
                    Scont = Regex.Replace(Scont, CLASSTag, "");
                }
                if (TagFONT)
                {
                    Scont = Regex.Replace(Scont, FONTTag, "");
                }
                if (TagSPAN)
                {
                    Scont = Regex.Replace(Scont, SPANTag, "");
                }

                if (TagIFRAME)
                {
                    Scont = Regex.Replace(Scont, IFRAMETag, "");
                }

                if (TagSCRIPT)
                {
                    Scont = Regex.Replace(Scont, SCRIPTTag, "");
                }

                if (TagHTML)
                {
                    Scont = Regex.Replace(Scont, HTMLTag, "");
                }



                

                #endregion 

               

                tttv.Value = Scont;
          }
            catch
            {
                Scont = "没有内容";
                tttv.Value = Scont;
            }


        }
        else
        {
            tt.Text = "查看内容为空 请确认步骤2";
           
        }
        
    }


    /// <summary>
    /// 格式化得到  页内容  的正 则
    /// </summary>
    /// <param name="Xstr">传入的字符</param>
    /// <returns></returns>
    public string RegexStrxCont(string Xstr)
    {
        return Xstr.Replace("[内容页内容]", @"[\W\w]+");

    }

    /// <summary>
    /// 格式化得到 页标题 
    /// </summary>
    /// <param name="Xstr">
    /// 传入正则
    /// </param>

    /// <returns></returns>
    public String RegexStrxContTitle(string Xstr)
    {
        return Xstr.Replace("[内容页标题]", @"[\W\w]+");
    }

    protected void Button1_ServerClick(object sender, EventArgs e)
    {

    }
}
